package com.example.netty.nio.zeroCpy.java传统io;

import java.io.*;
import java.net.Socket;

public class OldIOClient {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1", 7001);
        FileInputStream fileInputStream = new FileInputStream(new File("./dog.jpg"));

        DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
        byte[] bytes = new byte[4096];
        long readCount = 0;
        long total = 0;
        long startTime = System.currentTimeMillis();

        //读取文件，发送到server端
        while ((readCount = fileInputStream.read(bytes)) > 0) {
            total+=readCount;
            dataOutputStream.write(bytes);
        }

        // 结果：发送总字结：392715,耗时：4
        System.out.println("发送总字结："+total+",耗时："+(System.currentTimeMillis()-startTime));

        dataOutputStream.close();
        socket.close();
        fileInputStream.close();
    }
}


